package com.luoy.classloader;

import com.sun.tools.jdi.resources.jdi;
import sun.management.resources.agent;

import java.util.Arrays;
import java.util.List;
import java.util.Properties;

/**
 * @desc:
 * @author: luoy
 * @date: 2021-03-07 10:58
 */
public class TestLoader {


    public static void main(String[] args) {
       // bootClassLoaderLoadingPath();

      //  extClassLoaderLoadingPath();

       // appClassLoaderLoadingPath();

        // 当前类的类加载器  launcher类不开源
        System.out.println(TestLoader.class.getClassLoader());//sun.misc.Launcher$AppClassLoader@18b4aac2

        System.out.println(TestLoader.class.getClassLoader().getParent());//sun.misc.Launcher$ExtClassLoader@cc34f4d

        System.out.println(TestLoader.class.getClassLoader().getParent().getParent()); //null  为null说明已经到了启动类加载器
    }

    /**
     * @desc: 启动累加载器职责
     * @Author: luoy
     * @Date: 2021/3/7 11:00 上午
     */
    public static void bootClassLoaderLoadingPath(){

        // 获取启动类加载器的目录
        String property = System.getProperty("sun.boot.class.path");
        List<String> strings = Arrays.asList(property.split(":"));
        strings.forEach(System.out::println);

//        /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/resources.jar
//        /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/rt.jar
//        /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/sunrsasign.jar
//        /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/jsse.jar
//        /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/jce.jar
//        /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/charsets.jar
//        /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/jfr.jar
//        /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/classes 自己写的项目扔到此目录，可被系统类加载器加载
    }


    /**
     * @desc: 扩展类加载器
     * @Author: luoy
     * @Date: 2021/3/7 11:05 上午
     */
    public static void extClassLoaderLoadingPath(){

        String property = System.getProperty("java.ext.dirs");
        List<String> strings = Arrays.asList(property.split(":"));
        strings.forEach(System.out::println);

    }

    public static void appClassLoaderLoadingPath(){

        String property = System.getProperty("java.class.path");
        List<String> strings = Arrays.asList(property.split(":"));
        strings.forEach(System.out::println);

    }
}
